package com.xinghou.platform.dao.main.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import com.xinghou.platform.dao.bases.JdbcTemplate;
import com.xinghou.platform.dao.bases.database.CustomerContextHolder;
import com.xinghou.platform.dao.main.UserStatisticsDAO;
import com.xinghou.platform.model.main.UserStatistics;

/**
 * 
 * @author wzk
 *
 */
@Service
public class UserStatisticsDAOImpl  {/*
	@Resource
	private JdbcTemplate jdbcTemplate;
	
	@Override
	public UserStatistics getUserStatById(Integer statId) throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql = "SELECT Stat_id,Login_count,Last_login_time,Attention_count,Fans_count,Praise_count,Dynamic_count, Visit_count,"
				+ " Sale_count, Buy_count, Create_time,Update_time,Product_count,Project_count,Exposure_count FROM user_statistics WHERE Stat_id=?";
		UserStatistics userstat = jdbcTemplate.queryForObject(sql,new Object[] { statId }, new UserStatMapper());
		CustomerContextHolder.clearCustomerType();
		return userstat;
	}

	@Override
	public int updateUserStat(UserStatistics userstat) throws DataAccessException {
		String sql = "UPDATE user_statistics SET Login_count=?,Last_login_time=?,Attention_count=?,Fans_count=?,Praise_count=?,Dynamic_count=?, Visit_count=?,"
				+ "Sale_count = ?, Buy_count = ?,  Update_time=?,Product_count=?,Project_count=?,Exposure_count=? WHERE Stat_id=?";
		Object[] params = { userstat.getLoginCount(),userstat.getLastLoginTime(),userstat.getAttentionCount(),userstat.getFansCount(),userstat.getPraiseCount(),
						userstat.getDynamicCount(), userstat.getVisitCount(), userstat.getSaleCount(), userstat.getBuyCount(), userstat.getUpdateTime(),
						userstat.getProductCount(),userstat.getProjectCount(),userstat.getExposureCount(),userstat.getStatId()};
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_WRITE);
		int ret = jdbcTemplate.update(sql, params);
		CustomerContextHolder.clearCustomerType();
		return ret;
	}

	@Override
	public int saveUserStat(UserStatistics userstat) throws DataAccessException {
		String sql = "INSERT INTO user_statistics(Stat_id,Login_count,Last_login_time,Attention_count,Fans_count,Praise_count,Dynamic_count, Visit_count,"
				+ " Sale_count, Buy_count, Create_time,Update_time,Product_count,Project_count,Exposure_count) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		Object[] params = {userstat.getStatId(),userstat.getLoginCount(),userstat.getLastLoginTime(),userstat.getAttentionCount(),userstat.getFansCount(),
							userstat.getPraiseCount(),userstat.getDynamicCount(), userstat.getVisitCount(),userstat.getSaleCount(), userstat.getBuyCount(),
							userstat.getCreateTime(),userstat.getUpdateTime(),userstat.getProductCount(),userstat.getProjectCount(),userstat.getExposureCount()};
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_WRITE);
		int ret = jdbcTemplate.savenukey(sql.toString(),params);
		CustomerContextHolder.clearCustomerType();
		return ret;
	}

	private static final class UserStatMapper implements RowMapper<UserStatistics> {
		public UserStatistics mapRow(ResultSet rs, int rowNum) throws SQLException {
			UserStatistics userstat = new UserStatistics();
			userstat.setStatId(rs.getInt("Stat_id"));
			userstat.setLoginCount(rs.getInt("Login_count"));
			userstat.setLastLoginTime(rs.getTimestamp("Last_login_time"));
			userstat.setAttentionCount(rs.getInt("Attention_count"));
			userstat.setFansCount(rs.getInt("Fans_count"));
			userstat.setPraiseCount(rs.getInt("Praise_count"));
			userstat.setDynamicCount(rs.getInt("Dynamic_count"));
			userstat.setVisitCount(rs.getInt("Visit_count"));
			userstat.setSaleCount(rs.getInt("Sale_count"));
			userstat.setBuyCount(rs.getInt("Buy_count"));
			userstat.setCreateTime(rs.getTimestamp("Create_time"));
			userstat.setUpdateTime(rs.getTimestamp("Update_time"));
			userstat.setProductCount(rs.getInt("Product_count"));
			userstat.setProjectCount(rs.getInt("Project_count"));
			userstat.setExposureCount(rs.getInt("Exposure_count"));
			return userstat;
		}
	}

	@Override
	public List<UserStatistics> getUserStatisticsLists(int rowNum,
			Timestamp time) throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql = "SELECT Stat_id,Login_count,Last_login_time,Attention_count,Fans_count,Praise_count,Dynamic_count, Visit_count,"
				+ " Sale_count, Buy_count, Create_time,Update_time,Product_count,Project_count,Exposure_count FROM user_statistics WHERE Last_login_time<? ORDER BY Last_login_time DESC LIMIT ?";
		List<UserStatistics> list = jdbcTemplate.query(sql,new Object[] { time,rowNum }, new UserStatMapper());
		CustomerContextHolder.clearCustomerType();
		return list;
	}*/
}
